﻿using System;

class EncodeAString
{
    static void Main()
    {
        string text = "Когато бях овчарче и овците пасях...";
        string key = "ovtza";
        
        string encode = Encode(text, key);
        string decode = Decode(encode, key);

        Console.WriteLine(encode);
        Console.WriteLine(decode);
    }
  
    private static string Encode(string text, string key)
    {
        string encode = String.Empty;
        int indexKey = 0;

        for (int i = 0; i < text.Length; i++)
        {
            if (indexKey >= key.Length)
            {
                indexKey = 0;
            }
            encode += (char)(text[i] ^ key[indexKey]);
        }
        return encode;
    }

    private static string Decode(string text, string key)
    {
        string decode = String.Empty;
        int indexKey = 0;

        for (int i = 0; i < text.Length; i++)
        {
            if (indexKey >= key.Length)
            {
                indexKey = 0;
            }
            decode += (char)(text[i] ^ key[indexKey]);
        }
        return decode;
    }
}